<template>
  <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱" ref="target">
    <template #right>
      <XtxMore></XtxMore>
    </template>
    <ul class="goods-list" v-if="list.length === 0">
      <li v-for="i in 4" :key="i">
        <XtxSkeleton :width="306" :height="406" bg="#ccc" />
      </li>
    </ul>
    <ul class="goods-list" v-else>
      <li v-for="item in list" :key="item.id">
        <RouterLink :to="`/product/${item.id}`">
          <img :src="item.picture" alt="" />
          <p class="name">{{ item.name }}</p>
          <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
</template>

<script>
import { findHomeNew } from '@/api/home'
import HomePanel from './home-panel'
import { useObserver } from '@/compositions/index'
export default {
  components: { HomePanel },
  setup () {
    return new Promise((resolve, reject) => {
      const { list, target } = useObserver(findHomeNew)
      resolve({ list, target })
    })
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
